<?php
/**
 * Created by PhpStorm.
 * User: chenzhitao
 * Date: 2018/5/11
 * Time: 下午5:05
 */

namespace App\Busi\Modules\Resource;


use App\Busi\Modules\BaseBusi;
use App\Http\Requests\ThridUrlRo;
use App\Models\ThirdUrl;
use App\Models\UrlTag;

class ThridUrlListBusi extends BaseBusi
{
    public function handle(ThridUrlRo $ro){
        $where = [
            ['flag','=',1]
        ];
        $fields = ['id','name'];
        $tagList = UrlTag::where($where)->select($fields)->get();
        if($tagList){
            foreach ($tagList as &$item){
                $item['url_list'] = $this->getUrlListByTagId($item['id']);
            }
        }
        return $tagList;
    }
    public function getUrlListByTagId($tagId){
        $where = [
            ['tag_id','=',$tagId]
        ];
        $fields = ['title','url'];
        $data = ThirdUrl::where($where)->select($fields)->get();
        return $data;
    }
}